<?php	
class Obj_Location {
	
	protected static $t;
	
	public static function init() {
		self::$t = new Obj_DBTable_Locations();
	}
	
	public static function getLocations($city, $activeOnly = false) {
		$ar_ = self::$t->getLocations($city, $activeOnly);
		$ar = array();
		foreach ($ar_ as $k => $v) {
			$ar[$v['ID']] = $v;
		}
		return $ar;
	}
	
	public static function getAllLocations($activeOnly = false) {
		$ar_ = self::$t->getAllLocations($activeOnly);
		$ar = array();
		foreach ($ar_ as $k => $v) {
			$ar[$v['ID']] = $v;
		}
		return $ar;
	}
	
	public static function saveLocation($arData, $id) {
		if ($id == 0) {
			return self::$t->insert($arData);
		}
		else self::$t->update($arData, 'ID = '.intval($id));
		return intval($id);
	}
	
	public static function getLocation($id) {
		return self::$t->getLocation($id);
	}
	
	public static function findLocation($alias) {
		return self::$t->findLocation($alias);
	}
	
	public static function getLink($id) {
		$row = self::$t->getLinkRow($id);
		if (!$row) return false;
		$link = '/'.implode('/', array_reverse($row));
		return $link;
	}
	
} Obj_Location::init();

